/*

Author   : chaos

FileName : plus_operator.cpp

Date     : 12/08/17 17:31:45

*/
#include <iostream>
#include <cstring>


using namespace std;

class String
{
    private:
        char * string;
        long len;

    public:
        String();
        String(const char *);
        void show_string();
        String & operator = (const String &);
        String operator+ (String);

};

void String::show_string()
{
    cout << "string :" << string << " string's address :";
    cout << (void*) string ;

    cout << "length :" << len << endl;
}

String::String()
{
    len = 0;
    string = new char[len + 1];
    string[0] = '\0';
}

String::String(const char * i_string)
{
    len = strlen(i_string);
    string = new char [len + 1];
    strcpy(string,i_string);
}

String & String::operator=(const String &str)
{
    delete [] string;

    len = str.len;
    string = new char [len + 1];
    strcpy(string,str.string);

    return * this;
}

String String::operator+(String str)
{
    char * strbuf = new char [len + str.len + 1];

    strcpy(strbuf, string);
    strcat(strbuf, str.string);

    String retstr(strbuf);

    delete [] strbuf;

    return retstr;


}

int main(int argc ,char *argv[])
{
    String A_String("My ");
    String B_String("string") , C_String;

    C_String = A_String + B_String;

    C_String.show_string();
    return 0;
}
